<template>
	<view>
		<navbar :backshow="true" :title="title" :navBarHeight="navBarHeight" :menuRight="menuRight" :menuTop="menuTop"
			:menuHeight="menuHeight"></navbar>
		<!-- 头部展位 -->
		<view class="main" :style="{ height: mainheight + 'px' }"></view>
		<view class="noticexqbox">
			<view class="noticexqtime">
				{{ tgdata.auditTime }}
			</view>
			<view class="notiecdes" v-if="
          title != '预约通过' && noticedata.appointmentType == 'ROOM'
        ">
				<view class="notiecdess" v-if="title == '预约失败'">
					您在{{ tgdata.createTime }}提交的{{ tgdata.roomName }}房间预约请求在{{
            noticedata.createTime
          }}审核失败。
				</view>
			</view>
			<view class="notiecdes" v-if="title != '预约通过' && noticedata.appointmentType == 'DEVICE'">
				<view class="notiecdess" v-if="title == '预约失败'">
					您在提交的{{ formattedData(tgdata.deviceDetail) }}预约请求在{{
            noticedata.createTime
          }}审核失败。
				</view>
			</view>
			<view class="notiecdes" v-if="title != '预约通过' && title != '预约提醒'">
				<view class="notiecdess" v-if="title == '预约失败'">拒绝原因：</view>
				{{ noticedata.content }}
			</view>


			<view class="notiecdes" v-if="
          title == '预约通过' && noticedata.appointmentType == 'ROOM'
        ">
				您在{{ tgdata.createTime }}提交的{{ tgdata.roomName }}房间预约请求在{{
          tgdata.auditTime
        }}审核通过了，请做好准备，请注意维护房间卫生。
			</view>

			<view class="notiecdes" v-if="title == '预约通过' && noticedata.appointmentType == 'DEVICE'">
				您在{{ tgdata.createTime }}提交的{{formattedData(tgdata.deviceDetail)}}设备预约请求在{{
          tgdata.auditTime
        }}审核通过了。
			</view>

			<view class="notiecdes" v-if="title == '预约通过' || title == '预约提醒'">
				您的使用时段从{{ tgdata.startTime }}开始,于{{ tgdata.endTime }}结束。
			</view>
			<view class="notiecdes" v-if="title == '预约提醒' ">
				距离开始时间还有半小时，别忘记了。
			</view>
			<view class="notiecdes" v-if="title  == '预约通过' ">
				距离开始时间还有半小时，别忘记了。
			</view>
			<view class="notiecdes" v-if="title == '预约通过' && noticedata.appointmentType == 'ROOM'">
				使用后请记得带走您的随身物品，避免不必要的损失。
			</view>
			<view class="notiecdes" v-if="title == '预约通过' && noticedata.appointmentType == 'DEVICE'">
				使用后请记得及时归还，避免不必要的损失。
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: "通知详情",
				navBarHeight: 50, // 导航栏高度
				menuRight: 10, // 胶囊距右方间距（方保持左、右间距一致）
				menuTop: 50, // 胶囊距底部间距（保持底部间距一致）
				menuHeight: 0, // 胶囊高度（自定义内容可与胶囊高度保证一致）
				mainheight: 60,
				pageNum: 1,
				pageSize: 20,
				noticedata: {},
				tgdata: {}
			}
		},

		onLoad() {
			const that = this;
			// 获取系统信息
			const systemInfo = wx.getSystemInfoSync();
			// 胶囊按钮位置信息
			const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
			// 导航栏高度 = 状态栏高度 + 44
			that.navBarHeight = systemInfo.statusBarHeight + 44;
			that.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
			that.menuTop = menuButtonInfo.top;
			that.menuHeight = menuButtonInfo.height;
			that.mainheight = menuButtonInfo.top + menuButtonInfo.height;
			// 获取一下 最新数据
			uni.getStorage({
				key: "noticedata",
				success: (res) => {
					console.log("获取的数据：", res.data);
					// 可以在这里处理获取到的数据
					this.noticedata = res.data;
					if (res.data.appointmentId != '' || res.data.appointmentId != null) {
						this.title = res.data.title
					}
					// if (res.data.title == '预约通过') {
					// 	this.$myRequest({
					// 		url: "/client/appointment/getRoomAppointmentInfo",
					// 		method: "GET",
					// 		data: {
					// 			appointmentId: res.data.appointmentId
					// 		},
					// 	}).then((res) => {
					// 		console.log('获取预约详情', res.data);
					// 		this.tgdata = res.data
					// 		// console.log("房间回显", res.data.list, this.roomPhoto);
					// 	});
					// }

					if (res.data.appointmentType == 'ROOM_REMIND') {
						this.$myRequest({
							url: "/client/appointment/getRoomAppointmentInfo",
							method: "GET",
							data: {
								appointmentId: res.data.appointmentId
							},
						}).then((res) => {
							console.log('获取预约详情', res.data);
							this.tgdata = res.data
							// console.log("房间回显", res.data.list, this.roomPhoto);
						});
					}
					if (res.data.appointmentType == 'ROOM') {
						this.$myRequest({
							url: "/client/appointment/getRoomAppointmentInfo",
							method: "GET",
							data: {
								appointmentId: res.data.appointmentId
							},
						}).then((res) => {
							console.log('获取预约详情', res.data);
							this.tgdata = res.data
							// console.log("房间回显", res.data.list, this.roomPhoto);
						});
					}
					if (res.data.appointmentType == 'DEVICE') {
						this.$myRequest({
							url: "/client/appointment/getDeviceAppointmentInfo",
							method: "GET",
							data: {
								appointmentId: res.data.appointmentId
							},
						}).then((res) => {
							console.log('获取预约详情', res.data);
							this.tgdata = res.data
							// console.log("房间回显", res.data.list, this.roomPhoto);
						});
					}
					// this.getuser();

					this.$myRequest({
						url: "/client/appointmentUser/notifyRead",
						method: "GET",
						data: {
							notifyId: res.data.notifyId
						},
					}).then((res) => {

						// console.log("房间回显", res.data.list, this.roomPhoto);
					});

				},
				fail: function() {
					console.error("获取数据失败");
				},
			});

		},
		methods: {
			formattedData(deviceDetail) {
				// 假设 deviceDetail 是一个 JSON 字符串，需要先解析为对象
				const parsedData = JSON.parse(deviceDetail);

				// 格式化数据并返回
				return parsedData.map((item) => `${item.deviceName}*${item.number}`).join(',')
			}
		}


	}
</script>

<style></style>